I am building a web app where I detect the headphones button event. I succeeded in capturing headphones button event when they are plugged in. Now I am trying to capture Bluetooth headphones next button event. Any help on this please?
Code for headphone button detection.
document.addEventListener('volumeupbutton', () => {
//Do something here
}, false);
I need something similar to this.
Akansh :
You can use keydown and keyup events for implementing the long press functionality. \n\n\r\n\r\n// Imprementation of Long Press\r\n\r\nconst longPressTime = 1500;\r\nlet keyDownTimeout;\r\ndocument.addEventListener('keydown', e => {\r\n if (keyDownTimeout) {\r\n return;\r\n }\r\n keyDownTimeout = setTimeout(() => {\r\n // button was held for 1500ms, consider it a long-press\r\n if (e.code === 'ArrowUp') {\r\n console.log(\"Action Performed\");\r\n // do long-press action\r\n } else {\r\n console.log(\"Other action performed\");\r\n }\r\n }, longPressTime);\r\n});\r\n\r\ndocument.addEventListener('keyup', e => {\r\n clearTimeout(keyDownTimeout);\r\n keyDownTimeout = 0;\r\n});\r\nPress any key",
2019-08-06T07:09:15